package com.qr;

import java.sql.*;

/**
 *  Jdbc操作
 *      程序的耦合，程序之间的依赖
 *      类之间的依赖，方法之间的依赖
 */
public class Jdbc {
    public static void main(String[] args) throws Exception {
        //注册驱动，没有Mysql驱动这行连编译都无法通过
//        DriverManager.registerDriver(new com.mysql.jdbc.Driver());

        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/riskman?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull",
                "root", "root");
        String sql = "select * from sys_menu";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()){
            int menu_id = resultSet.getInt("menu_id");
            String menu_name = resultSet.getString("menu_name");
            int parent_id = resultSet.getInt("parent_id");
            int order_num = resultSet.getInt("order_num");
            System.out.println(menu_id+""+  menu_name+" " +parent_id + " " + order_num);
        }
    }
}
